package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAppType;
import com.ruoyi.system.service.ISysAppTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统应用类型Controller
 * 
 * @author ning
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/system/appType")
public class SysAppTypeController extends BaseController
{
    @Autowired
    private ISysAppTypeService sysAppTypeService;

    /**
     * 查询系统应用类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:appType:list')")
    @GetMapping("/list")
    public AjaxResult list(SysAppType sysAppType)
    {
        List<SysAppType> list = sysAppTypeService.selectSysAppTypeList(sysAppType);
        return success(list);
    }

    /**
     * 导出系统应用类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:appType:export')")
    @Log(title = "系统应用类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppType sysAppType)
    {
        List<SysAppType> list = sysAppTypeService.selectSysAppTypeList(sysAppType);
        ExcelUtil<SysAppType> util = new ExcelUtil<SysAppType>(SysAppType.class);
        util.exportExcel(response, list, "系统应用类型数据");
    }

    /**
     * 获取系统应用类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysAppTypeService.selectSysAppTypeById(id));
    }

    /**
     * 新增系统应用类型
     */
    @PreAuthorize("@ss.hasPermi('system:appType:add')")
    @Log(title = "系统应用类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAppType sysAppType)
    {
        sysAppType.setCreateBy(getUsername());
        return toAjax(sysAppTypeService.insertSysAppType(sysAppType));
    }

    /**
     * 修改系统应用类型
     */
    @PreAuthorize("@ss.hasPermi('system:appType:edit')")
    @Log(title = "系统应用类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAppType sysAppType)
    {
        sysAppType.setUpdateBy(getUsername());
        return toAjax(sysAppTypeService.updateSysAppType(sysAppType));
    }

    /**
     * 删除系统应用类型
     */
    @PreAuthorize("@ss.hasPermi('system:appType:remove')")
    @Log(title = "系统应用类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAppTypeService.deleteSysAppTypeByIds(ids));
    }
}
